<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\SemiFinishProductRep;
use Illuminate\Http\Request;

class SemiFinishProduct extends Controller
{
    //半成品管理
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new SemiFinishProductRep();
    }

    /**
     * 获取列表
     * @param Request $request
     */
    public function getSemiFinishProductList(Request $request){
        $params = $request->only(['warehouse_id','modelid','product_id','spucification_id','model_number_id']);
        $data = $this->rep->getSemiFinishProductListRep($params);
        return re(0,$data,'success');
    }

    public function getSemiFinishProductInfo(Request $request){
        $params = $request->only(['product_id','warehouse_id','page_name','model_number_id']);
        $data = $this->rep->getSemiFinishProductInfoRep($params);
        return re(0,$data,'success');
    }

    public function getSemiFinishProductInfoList(Request $request){
        $params = $request->only(['product_id','warehouse_id','specification_id','model_number_id']);
        $data = $this->rep->getSemiFinishProductInfoListRep($params);
        return re(0,$data,'success');
    }


    /**
     * 半成品加入成品库
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addFinishProduct(Request $request){
        $params = $request->all();
        $data = $this->rep->addFinishProductRep($params);
        return re($data['code'],'',$data['msg']);
    }

    public function getInventoryCount(Request $request){
        $params = $request->only(['product_id','model_number_id','specification_id','color_id','warehouse_id','goods_shelf']);
        $product_id = $params['product_id']??'';
        $model_number_id = $params['model_number_id']??'';
        $specification_id = $params['specification_id']??"";
        $color_id = $params['color_id']??'';
        $warehouse_id = $params['warehouse_id']??'';
        $goods_shelf = $params['goods_shelf']??'';
        $count = $this->rep->getInventoryCountRep($product_id,$model_number_id,$specification_id,$color_id,$warehouse_id,$goods_shelf);
        return re(0,$count,'success');
    }

    /**
     * 删除半成品
     * @param Request $request
     * @return void
     */
    public function delSemiFinishProduct(Request $request){
        $params = $request->only(['ids','user_id']);
        $data = $this->rep->delSemiFinishProductRep($params);
        return re($data['code'],'',$data['msg']);
    }

}
